/*
 * Copyright (c) 2014 laidian. All Rights Reserved.
 * 
 * @author yaoyuming
 * 
 * @date 2020/8/28 0028
 */
package com.yao.common.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import com.baomidou.mybatisplus.core.toolkit.ArrayUtils;

/**
 * spring profile 工具类 获取当前active
 * 
 * @author yaoyuming
 * @date 2020/8/28 0028 16:13
 */
@Component
public class ProfileUtils implements ApplicationContextAware {

    private static ApplicationContext context;

    /**
     * 功能描述 : 获取当前环境的active profile.
     *
     * @param
     * @author yaoyuming
     * @date 2020/8/28 0028
     * @return {@link String}
     */
    public static String getActiveProfile() {
        String[] activeProfiles = context.getEnvironment().getActiveProfiles();
        if (!ArrayUtils.isEmpty(activeProfiles)) {
            return activeProfiles[0];
        }
        return "";
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        context = applicationContext;
    }
}